package cn.haiway.drools.service;

import cn.haiway.drools.pojo.Fact;
import cn.haiway.drools.respository.FactRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * Service Implementation for managing RuleObject.
 */
@Service
@Slf4j
public class FactService {

    @Autowired
    private FactRepository factRepository;

    public Fact save(Fact fact) {
        log.debug("Request to save RuleObject : {}", fact);
        return factRepository.save(fact);
    }

    public List<Fact> findByProjectId(String projectId){
        Fact ruleObject = new Fact();
        ruleObject.setProjectId(projectId);
        Example<Fact> ruleObjectExample = Example.of(ruleObject);
        List<Fact> ruleObjects = factRepository.findAll(ruleObjectExample);
        return ruleObjects;
    }

    public Optional<Fact> findOne(String id) {
        log.debug("Request to get RuleObject : {}", id);
        return factRepository.findById(id);
    }


    public void delete(String id) {
        log.debug("Request to delete RuleObject : {}", id);
        factRepository.deleteById(id);
    }
}
